<template>
	<view>
		<yichangCommon v-if="loading2"
		    :order="order" :Record="Record"
			:customStyle1="customStyle1" :customStyle11="customStyle11" 
			:customStyle2="customStyle2" :customStyle3="customStyle3">
		</yichangCommon>
		
		<block v-if="loading2">

			<view v-show="Record.is_situation==0">
				<view v-show="Record.user_id == order.user_id">
					<view style="margin-top: 10rpx;padding-bottom: 20rpx;width: 94%;margin-left: 3%;">
						<u-button  style="float: right;margin-right: 5rpx;" :custom-style="customStyle3" hover-class="none" :disabled="subDisabled" type="primary"
							>
							{{ $t('等待对方处理') }}
						</u-button>
						
						<u-button  @click="lianxi(handle_user.mobile)" style="float: right;margin-right: 15rpx;" :custom-style="customStyle1" hover-class="none" :disabled="subDisabled" type="primary"
							>
							{{ $t('即时联系') }}
						</u-button>
						<view style="clear: both;"></view>
					</view>
				</view>
				
				<view v-show="Record.user_id != order.user_id">
					
					<!--无关联订单-->
					<view v-show="is_relation_order==0" style="margin-top: 10rpx;padding-bottom: 20rpx;width: 94%;margin-left: 3%;">
						<u-button v-if="order.orderInfo.terminate_status==0" @click="jixu" style="float: right;margin-right: 10rpx;" :custom-style="customStyle1" hover-class="none" :disabled="subDisabled" type="primary"
							>
							{{ $t('继续交易') }}
						</u-button>
						
						<u-button @click="shenqing" style="float: right;margin-right: 10rpx;" :custom-style="customStyle11" hover-class="none" :disabled="subDisabled" type="primary"
							>
							{{ $t('终止交易') }}
						</u-button>
						
						<u-button  @click="lianxi(lianxi_user.mobile)" style="float: right;margin-right: 10rpx;" :custom-style="customStyle11" hover-class="none" :disabled="subDisabled" type="primary"
							>
							{{ $t('即时联系') }}
						</u-button>
						<view style="clear: both;"></view>
					</view>
					
					
					<!--有关联订单-->
					<view  v-show="relation_order&&relation_order.length!=0&&is_relation_order==1"  class="cardBox">
						<view class="flex" style="margin-top: 10rpx;">
							<view class="biao">
								<span class="biao_span">|</span> 
								<text style="font-size: 32rpx;">{{$t('请选择处理方式')}} </text> 
							</view>
						</view>
						
						
						<view class="flex" style="margin-top: 30rpx;margin-bottom: 30rpx;">
							<view class="biao">
								<text style="font-size: 24rpx;font-weight: 500;">{{$t('关联订单')}} ：</text> 
							</view>
						</view>
						<view v-if="relation_order&&relation_order.length!=0&&relation_order.orderInfo.type === 'goods'">
							<ItemGoods v-if="loading" :isOrder="true" :isRow="1" :orderDetail="relation_order.orderInfo" :item="relation_order.orderInfo.release_info" :type="2">
								<template v-slot:btns>
									<view style="margin-top: 10rpx;padding-bottom: 20rpx;width: 98%;margin-left: 1%; ">
										<u-button v-if="relation_order.orderInfo.is_margin==2&&relation_order.orderInfo.status==10" @click="shouhou" style="float: right;margin-right: 10rpx;" :custom-style="customStyle1" hover-class="none" :disabled="subDisabled" type="primary"
											>
											{{ $t('售后') }}
										</u-button>
										
										<!-- <u-button v-if="relation_order.orderInfo.terminate_status==0" @click="jixu2(relation_order)" style="float: right;margin-right: 10rpx; " :custom-style="customStyle1" hover-class="none" :disabled="subDisabled" type="primary"
											>
											{{ $t('继续交易') }}
										</u-button> -->
										
										<u-button @click="shenqing2" style="float: right;margin-right: 10rpx; " :custom-style="customStyle11" hover-class="none" :disabled="subDisabled" type="primary"
											>
											{{ $t('终止交易') }}
										</u-button>
										
										<u-button  @click="lianxi(lianxi_user2.mobile)" style="float: right;margin-right: 10rpx; " :custom-style="customStyle11" hover-class="none" :disabled="subDisabled" type="primary"
											>
											{{ $t('即时联系') }}
										</u-button>
										<view style="clear: both;"></view>
									</view>
								</template>
							</ItemGoods>
						</view>
						<view v-if="relation_order&&relation_order.length!=0&&relation_order.orderInfo.type === 'transport'">
							<ItemTransportList v-if="loading" @click="detail()" :isOrder="true" :isRow="1" :orderDetail="relation_order.orderInfo" :item="relation_order.orderInfo.release_info" :type="2">
								<template v-slot:btns>
									<view style="margin-top: 10rpx;padding-bottom: 20rpx;width: 98%;margin-left: 1%; ">
										<u-button v-if="relation_order.orderInfo.is_margin==2&&relation_order.orderInfo.status==10" @click="shouhou" style="float: right;margin-right: 10rpx; " :custom-style="customStyle1" hover-class="none" :disabled="subDisabled" type="primary"
											>
											{{ $t('售后') }}
										</u-button>
										
										<!-- <u-button v-if="relation_order.orderInfo.terminate_status==0" @click="jixu2(relation_order)" style="float: right;margin-right: 10rpx; " :custom-style="customStyle1" hover-class="none" :disabled="subDisabled" type="primary"
											>
											{{ $t('继续交易') }}
										</u-button> -->
										
										<u-button @click="shenqing2" style="float: right;margin-right: 10rpx; " :custom-style="customStyle11" hover-class="none" :disabled="subDisabled" type="primary"
											>
											{{ $t('终止交易') }}
										</u-button>
										
										<u-button  @click="lianxi(lianxi_user2.mobile)" style="float: right;margin-right: 10rpx; " :custom-style="customStyle11" hover-class="none" :disabled="subDisabled" type="primary"
											>
											{{ $t('即时联系') }}
										</u-button>
										<view style="clear: both;"></view>
									</view>
								</template>
							</ItemTransportList>
						</view>
						<view v-if="relation_order&&relation_order.length!=0&&relation_order.orderInfo.type === 'crossborder'">
							<ItemFreightForwarder v-if="loading" @click="detail()" :isOrder="true" :isRow="1" :orderDetail="relation_order.orderInfo" :item="relation_order.orderInfo.release_info" :type="2">
								<template v-slot:btns>
									<view style="margin-top: 10rpx;padding-bottom: 20rpx;width: 98%;margin-left: 1%; ">
										<u-button v-if="relation_order.orderInfo.is_margin==2&&relation_order.orderInfo.status==10" @click="shouhou" style="float: right;margin-right: 10rpx; " :custom-style="customStyle1" hover-class="none" :disabled="subDisabled" type="primary"
											>
											{{ $t('售后') }}
										</u-button>
										
										<!-- <u-button v-if="relation_order.orderInfo.terminate_status==0" @click="jixu2(relation_order)" style="float: right;margin-right: 10rpx; " :custom-style="customStyle1" hover-class="none" :disabled="subDisabled" type="primary"
											>
											{{ $t('继续交易') }}
										</u-button> -->
										
										<u-button @click="shenqing2" style="float: right;margin-right: 10rpx; " :custom-style="customStyle11" hover-class="none" :disabled="subDisabled" type="primary"
											>
											{{ $t('终止交易') }}
										</u-button>
										
										<u-button  @click="lianxi(lianxi_user2.mobile)" style="float: right;margin-right: 10rpx; " :custom-style="customStyle11" hover-class="none" :disabled="subDisabled" type="primary"
											>
											{{ $t('即时联系') }}
										</u-button>
										<view style="clear: both;"></view>
									</view>
								</template>
							</ItemFreightForwarder>
						</view>
						
						
						
						<view class="flex" style="margin-top: 30rpx;margin-bottom: 30rpx;">
							<view class="biao">
								<text style="font-size: 24rpx;font-weight: 500;">{{$t('当前订单')}} ：</text> 
							</view>
						</view>
						<view v-if="order.orderInfo.type === 'goods'">
							<ItemGoods v-if="loading" :isOrder="true" :isRow="1" :orderDetail="order.orderInfo" :item="order.orderInfo.release_info" :type="2">
								<template v-slot:btns>
									<view style="margin-top: 10rpx;padding-bottom: 20rpx;width: 98%;margin-left: 1%; ">
										<u-button v-if="order.orderInfo.terminate_status==0" @click="jixu" style="float: right;margin-right: 10rpx; " :custom-style="customStyle1" hover-class="none" :disabled="subDisabled" type="primary"
											>
											{{ $t('继续交易') }}
										</u-button>
										
										<u-button @click="shenqing" style="float: right;margin-right: 10rpx; " :custom-style="customStyle11" hover-class="none" :disabled="subDisabled" type="primary"
											>
											{{ $t('终止交易') }}
										</u-button>
										
										<u-button  @click="lianxi(lianxi_user.mobile)" style="float: right;margin-right: 10rpx; " :custom-style="customStyle11" hover-class="none" :disabled="subDisabled" type="primary"
											>
											{{ $t('即时联系') }}
										</u-button>
										<view style="clear: both;"></view>
									</view>
								</template>
							</ItemGoods>
						</view>
						<view v-if="order.orderInfo.type === 'transport'">
							<ItemTransportList v-if="loading" @click="detail()" :isOrder="true" :isRow="1" :orderDetail="order.orderInfo" :item="order.orderInfo.release_info" :type="2">
								<template v-slot:btns>
									<view style="margin-top: 10rpx;padding-bottom: 20rpx;width: 98%;margin-left: 1%; ">
										<u-button v-if="order.orderInfo.terminate_status==0" @click="jixu" style="float: right;margin-right: 10rpx; " :custom-style="customStyle1" hover-class="none" :disabled="subDisabled" type="primary"
											>
											{{ $t('继续交易') }}
										</u-button>
										
										<u-button @click="shenqing" style="float: right;margin-right: 10rpx; " :custom-style="customStyle11" hover-class="none" :disabled="subDisabled" type="primary"
											>
											{{ $t('终止交易') }}
										</u-button>
										
										<u-button  @click="lianxi(lianxi_user.mobile)" style="float: right;margin-right: 10rpx; " :custom-style="customStyle11" hover-class="none" :disabled="subDisabled" type="primary"
											>
											{{ $t('即时联系') }}
										</u-button>
										<view style="clear: both;"></view>
									</view>
								</template>
							</ItemTransportList>
						</view>
						<view v-if="order.orderInfo.type === 'crossborder'">
							<ItemFreightForwarder v-if="loading" @click="detail()" :isOrder="true" :isRow="1" :orderDetail="order.orderInfo" :item="order.orderInfo.release_info" :type="2">
								<template v-slot:btns>
									<view style="margin-top: 10rpx;padding-bottom: 20rpx;width: 98%;margin-left: 1%; ">
										<u-button v-if="order.orderInfo.terminate_status==0" @click="jixu" style="float: right;margin-right: 10rpx; " :custom-style="customStyle1" hover-class="none" :disabled="subDisabled" type="primary"
											>
											{{ $t('继续交易') }}
										</u-button>
										
										<u-button @click="shenqing" style="float: right;margin-right: 10rpx; " :custom-style="customStyle11" hover-class="none" :disabled="subDisabled" type="primary"
											>
											{{ $t('终止交易') }}
										</u-button>
										
										<u-button  @click="lianxi(lianxi_user.mobile)" style="float: right;margin-right: 10rpx;" :custom-style="customStyle11" hover-class="none" :disabled="subDisabled" type="primary"
											>
											{{ $t('即时联系') }}
										</u-button>
										<view style="clear: both;"></view>
									</view>
								</template>
							</ItemFreightForwarder>
						</view>
						
						
						
						
						
					</view>
				
				
				
				</view>
			</view>
			
			<view v-show="Record.is_situation!=0">
				<view class="cardBox" style="margin-top: 10rpx;">
					<view style="margin-top: 10rpx;padding-bottom: 20rpx;">
						<text style="font-weight: bold;font-size:32rpx;">{{text.submit_user}} </text>
						<view class="flex">
							<image :src="IMAGE_URL+handle_user.avatar" class="close_image2"></image>
							<view style="line-height: 140rpx;float: left;">
								<view v-show="lang==='zh'">{{handle_user.username}}</view>
								<view v-show="lang==='ru'">{{handle_user.username_ru}}</view>
							</view>
						</view>
						
						<view v-show="Record.is_situation==1">
							<view class="flex" style="margin-top: 20rpx;">
								<view v-show="Record.is_agree_speed==0">{{ $t('已选择继续交易') }}</view>
								<view v-show="Record.is_agree_speed==1">{{ $t('已同意申请时效') }}</view>
								<view v-show="Record.is_agree_speed==2">{{ $t('已拒绝申请时效') }}</view>
							</view>
						</view>
						<view v-show="Record.is_situation==2">
							<view class="flex" style="margin-top: 20rpx;">
								{{ $t('已申请终止交易') }}
							</view>
						</view>
						
						<view class="flex" style="margin-top: 10rpx;padding-bottom: 20rpx;color: #999;">
							<view style="width: 50%;float: left; text-align: left;" v-if="order.orderInfo.terminate_transaction_time">
								{{timestampToDate(order.orderInfo.terminate_transaction_time*1000)}}
							</view>
							<view style="width: 50%;float: left; text-align: left;" v-else>
								{{timestampToDate(Record.is_situation_time*1000)}}
							</view>
						</view>
					</view>
				</view>
				
				<view style="margin-top: 10rpx;padding-bottom: 20rpx;width: 94%;margin-left: 3%;">
					<u-button  @click="lianxi(lianxi_user.mobile)" style="float: right;margin-right: 10rpx;" :custom-style="customStyle11" hover-class="none" :disabled="subDisabled" type="primary"
						>
						{{ $t('即时联系') }}
					</u-button>
					<view style="clear: both;"></view>
				</view>
			</view>
			
		</block>
		
		<u-popup v-model="jixu_show"  mode="bottom" :closeable="true" >
			<view style="height: 50px;"></view>
			<u-button  @click="caozuo(1)" style="width:250px" :custom-style="customStyle1" hover-class="none" :disabled="subDisabled" type="primary"
				>
				{{ $t('同意调整时效') }}
			</u-button>
			
			<u-button  @click="caozuo(2)" style="width:250px" :custom-style="customStyle11" hover-class="none" :disabled="subDisabled" type="primary"
				>
				{{ $t('拒绝调整时效') }}
			</u-button>
			
			<!-- <button @click="guanbi" style="margin-top: 50rpx;width: 80%;">
				{{$t('关闭')}}
			</button> -->
			
			<view style="height: 100px;"></view>
		</u-popup>
		
		
		
		
		<view style="height: 50px;"></view>
	</view>
</template>

<script>
	import yichangCommon from './yichangCommon.vue';
	import ItemGoods from "@/components/detail/GoodsItem2.vue";
	import ItemAgencyList from '@/components/detail/AgencyListItem.vue'
	import ItemTransportList from "@/components/detail/TransportListItem.vue";
	import ItemFreightForwarder from '@/components/detail/FreightForwarderItem.vue'
	import {HTTP_REQUEST_URL,HTTP_IMG_UTL,IMAGE_URL} from "@/config/app";
	
	import {
		ImageUrl,
		isVideo,
		time,createC2CConversation
	} from "@/common/public";
	export default {
		components:{
			yichangCommon,
			ItemGoods,
			ItemAgencyList,
			ItemTransportList,
			ItemFreightForwarder
		},
		props:{
			order:{
				type:Object,
				default:{}
			},
			Record2:{
				type:Object,
				default:{}
			},
			
			customStyle1:{
				type:Object,
				default:{}
			},
			customStyle11:{
				type:Object,
				default:{}
			},
			customStyle2:{
				type:Object,
				default:{}
			},
			customStyle3:{
				type:Object,
				default:{}
			},
		},
		data() {
			return {
				//远程域名
				HTTP_IMG_UTL,
				HTTP_REQUEST_URL,
				IMAGE_URL,
				url: IMAGE_URL,
				
				//语言
				lang: this.$i18n.locale,
				
				img:HTTP_IMG_UTL+'huangjin.png',
				subDisabled:false,
				disabled:false,
				jixu_show:false,
				loading:false,
				loading2:false,
				
				text:{
					submit_user:this.$t('提交人')
				},
				
				//记录
				Record:{},
				
				//是否有无关联订单
				is_relation_order:0,
				relation_order:{
					orderInfo:{
						type:'goods',
						release_info:[]
					}
				},
				
				lianxi_user:{},
				lianxi_user2:{},
				
				handle_user:{}
			}
		},
		mounted(){
			this.Record = this.Record2
			
			//通过我的user_id 来找 对方联系人
			if(this.order.release_user.id != this.order.user_id){
				this.lianxi_user = this.order.release_user
			}else{
				this.lianxi_user = this.order.join_user
			}
			
			//通过记录发起者 user_id 来找 被处理人
			if(this.Record.user_id != this.order.release_user.id){
				this.handle_user = this.order.release_user
			}else{
				this.handle_user = this.order.join_user
			}
			
			var that = this
			that.$u.api.order.abnormalRelatedOrders({
				order_id: that.order.orderInfo.id,
				main_order:that.order.orderInfo.main_order,
			}).then(result => {
				if((result)&&(result.length!=0)){
					that.is_relation_order=1
					that.relation_order=result
					
					if( that.relation_order.release_user.id != that.relation_order.user_id){
						that.lianxi_user2 = that.relation_order.release_user
					}else{
						that.lianxi_user2 = that.relation_order.join_user
					}
					that.loading = true
				}
				that.loading2 = true
			})

		},
		methods:{
			lianxi(mobile){
				createC2CConversation(mobile,this)
			},
			caozuo(i){
				var that = this
				that.$u.api.order.yichangJixu({
					id: that.Record.id,
					is_agree_speed: i,
					lang:that.lang
				}).then(result => {
					console.log(result)
					uni.showModal({
						content: that.$t('操作成功'),
						showCancel: false,
						confirmText: that.$t('是'),
					})
					setTimeout(function() {					
						that.jixu_show=false
						that.Record.is_situation=1
						that.Record.is_agree_speed=i
						that.$emit('change','abnormal','yichangJixu',result)
					}, 2000);
				})
			},
			jixu(){
				var flag = 0;
				var that = this;
				if(this.Record.abnormal_issues=='他人异常'){
					if(this.Record.abnormal_cause=='超时交接'){
						flag = 1;
					}
				}
				if(flag==1){
					this.jixu_show=true
				}else{
					that.$u.api.order.yichangJixu({
						id: that.Record.id,
						lang:that.lang
					}).then(result => {
						console.log(result)
						uni.showModal({
							content: that.$t('操作成功'),
							showCancel: false,
							confirmText: that.$t('是'),
						})
						setTimeout(function() {
							that.Record.is_situation=1
							that.$emit('change','abnormal','yichangJixu',result)
						}, 2000);
					})
				}
				
			},
			
			jixu2(order){
				console.log(order)
				uni.navigateTo({
					url:"/pages/abnormal/index?join_order_id="+order.orderInfo.join_order_id+"&situation_id="+order.orderInfo.situation_id+"&is_list=1"+'&order_id='+order.orderInfo.id
				})
			},
			detail(){
				this.$u.route({
					url: "/pages/ordering/orderDetail",
					params: {
						id: this.order.orderInfo.id,
						join_order_id:this.order.orderInfo.join_order_id,
					}
				})
			},
			guanbi(){
				this.jixu_show=false
			},
			shouhou(){
				uni.navigateTo({
					url:'/pages/customer/customer?order_id='+this.relation_order.orderInfo.id+'&join_order_id='+this.relation_order.orderInfo.join_order_id
				})
			},
			shenqing(){
				uni.navigateTo({
					url:"/pages/ordering/stopOrder?order_id="+this.order.orderInfo.id+"&join_order_id="+this.order.orderInfo.join_order_id+"&situation_id="+this.Record.id
				})
			},
			shenqing2(){
				uni.navigateTo({
					url:"/pages/ordering/stopOrder?order_id="+this.relation_order.orderInfo.id+"&join_order_id="+this.relation_order.orderInfo.join_order_id
				})
			},
			timestampToDate(timestamp) {
			  const date = new Date(timestamp); // 如果timestamp是数值，可以直接作为Date构造函数的参数
			  const year = date.getFullYear();
			  const month = (date.getMonth() + 1).toString().padStart(2, '0');
			  const day = date.getDate().toString().padStart(2, '0');
			  const hours = date.getHours().toString().padStart(2, '0');
			  const minutes = date.getMinutes().toString().padStart(2, '0');
			  const seconds = date.getSeconds().toString().padStart(2, '0');
			  return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
			},
		}
	}
</script>

<style lang="css">
	.cardBox {
		width: 94%;
		margin: 0 auto;
		margin-top: 30rpx;
		box-shadow: 0 0 10px #ddd;
		background: #ddd;
		padding: 10rpx 20rpx;
		border-radius: 20rpx;
		background: #fff;
		margin-bottom: 30rpx;
		position: relative;
	}
	.flex{width: 100%;display: flex;}
	.biao{margin-top: 0rpx; width: 80%; margin-left: 0rpx;font-size: 30rpx;  font-weight: bold;}
	.biao_span{color:darkorange ; font-size: 18px; margin-right: 5px;}
	.cardTitle{font-size: 24rpx; width: 94%;padding-top: 6rpx;}
	.order_img{width: 160rpx;height: 160rpx;border-radius: 20rpx;}
	.close_image2{
		width: 120rpx;height: 120rpx;border-radius: 20rpx; margin-right: 20rpx; margin-top: 20rpx; float: left;
	}
</style>